package com.shoponline.dao.impl;


import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.shoponline.dao.UserDAO;
import com.shoponline.po.User;

public class UserDaoImpl extends HibernateDaoSupport implements UserDAO{

	@Override
	public User checkLogin(String email, String password) {
		
		String[] str = {email,password};
		List<User> list = getHibernateTemplate().find("from User where EMAIL=? and PASSWORD=?",str);
		User user = null;
		if(list.size()>0){
			
			user = (User) list.get(0);
			
		}
		return user;
	}

	@Override
	public boolean checkUserName(String username) {
		
		List<User> list = getHibernateTemplate().find("from User where username=?",username);
	
		if(list.size()>0){
			
			return false;
			
		}
		return true;
		
	}

	@Override
	public void saveUser(User user) throws DataAccessException{
		
		this.getHibernateTemplate().save(user);
		
	}

	@Override
	public void updateUser(User user) {
		
		this.getHibernateTemplate().update(user);
		
	}

	@Override
	public boolean checkEmail(String email) {
		
		List<User> list = this.getHibernateTemplate().find("from User where email=?",email);
		if(list.size()>0){
			
			return false;
		}
		return true;
	}
	
	
	
	
	
}
